package com.wanmait.recycle.util;

public class Pager {
	public static final int DEFAULT_PAGE_SIZE = 2;
	private int pageNo;
	private int dataCount;
	private int pageSize = DEFAULT_PAGE_SIZE;
	public int getPageNo() {
		if(pageNo>this.getPageCount()) {
			pageNo = this.getPageCount();
		}
		if(pageNo<1) pageNo = 1;
		return pageNo;
	}
	public void setPageNo(String pageNo) {
		System.out.println("setPageNostr........."+pageNo);
		this.pageNo = 1;
		try{
			this.pageNo = Integer.parseInt(pageNo);
		}catch(Exception e) {}
	}
	public void setPageNo(int pageNo) {
		System.out.println("setPageNo..........."+pageNo);
		this.pageNo = pageNo;
	}
	public int getDataCount() {
		return dataCount;
	}
	public void setDataCount(int dataCount) {
		this.dataCount = dataCount;
	}
	public int getPageSize() {
		return pageSize;
	}
	public int getFirstRow() {
		return (this.getPageNo()-1)*this.getPageSize();
	}
	public void setPageSize(int pageSize) {
		if(pageSize<=0) pageSize = DEFAULT_PAGE_SIZE;
		this.pageSize = pageSize;
	}
	public int getPageCount() {
		return dataCount/pageSize+(dataCount%pageSize==0?0:1);
	}
}
